package com.itheima.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ServletDemo1")
public class ServletDemo1 extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取项目的虚拟路径
        String contextPath = req.getContextPath();
        System.out.println("contextPath = " + contextPath);

        // 获取项目的真实路径
        String servletPath = req.getServletPath();
        System.out.println("servletPath = " + servletPath);

        // 获取客户端的ip地址
        String ip = req.getRemoteAddr();
        System.out.println("ip = " + ip);

        // 获取客户端的数据
        String queryString = req.getQueryString();
        System.out.println("queryString = " + queryString);

        // 获取请求路径
        String requestURI = req.getRequestURI();
        System.out.println("requestURI = " + requestURI);

        // 获取请求的全部路径
        StringBuffer requestURL = req.getRequestURL();
        System.out.println("requestURL = " + requestURL);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
